package org.s170.servlet.WebServlet;

import org.s170.dao.UserDao;
import org.s170.entity.User;
import org.s170.servlet.BaseServlet;
import org.s170.utils.JwtUtil;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/main.do")
public class MainServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取客户端发送过来的token
        // String token = req.getParameter("token");
        String token = req.getHeader("Authorization");

        // 获取payload信息
        String username = JwtUtil.getPayload(token, "username", String.class);

        // 模拟DAO，查询当前登录用户信息
        UserDao userDao = new UserDao();
        User user = userDao.getIDFindUser(username);

        // 响应客户端
        print(resp, successJson(user));
    }
}
